import React, { Component } from 'react';

class App extends Component {
  incIfOdd = () => {
    if(this.props.value % 2 !== 0){
      this.props.onInc();
    }
  }

  incAsync = () =>{
    setTimeout(this.props.onInc,1000);
  }
  render() {
    const { value, onInc, onDec } = this.props;
    return (
      <p>
        点击了: {value} 次
        {' '}
        <button onClick={onInc}>
          +
        </button>
        {' '}
        <button onClick={onDec}>
          -
        </button>
        {' '}
        <button onClick={this.incIfOdd}>
        奇数+1
        </button>
        {' '}
        <button onClick={this.incAsync}>
        异步+1
        </button>
      </p>
    )
  }
}

export default App;
